package test;

import java.util.HashMap;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Description
 * @Author Firenut
 * @Date 2023-07-31 21:38
 */
public class Apple {
    private String color;

    public Apple(String color) {
        this.color = color;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (!(obj instanceof Apple)) return false;
        if (obj == this) return true;
        return this.color.equals(((Apple) obj).color);
    }

    public static void main(String[] args) {
        Apple a1 = new Apple("green");
        Apple a2 = new Apple("red");
        HashMap<Apple, Integer> m = new HashMap<>();
        m.put(a1, 10);
        m.put(a2, 10);
        System.out.println(m.get(new Apple("green"))); // null
        System.out.println(m.get(a1)); // 10
        System.out.println(m.get(null)); // null
    }
}
